package com.cskaoyan.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author stone
 * @date 2022/08/06 10:56
 */
@Controller
public class HelloController {

    @RequestMapping("hello1")
    public ModelAndView hello1() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/hello.jsp");
        // model提供的是键值对 → key在视图文件中 ${}来引用key
        modelAndView.addObject("name", "ligenli!");
        return modelAndView;
    }

    // 如果返回值为String，这个字符串作为ModelAndView中的ViewName
    @RequestMapping("hello2")
    public String hello2(Model model) {
        model.addAttribute("name", "tianming");
        return "/hello.jsp";
    }
}
